/**
 * Created by L on 2017/6/3.
 */

var url = window.location.host;
url = "http://" + url + "/qktPipeline/public";

function myclick(str,item){
       $("#item03").html(item) ;
        $.ajax({
        data:{id:str},   
        url:url+"/find_assets",
        type:'GET',
        dataType:'JSON',
        success:function (text) {
             tabledata(text);
        },
        error:function () {

        }
    });
}

function screenclick(str,item){
       $("#item03").html(item) ;
        $.ajax({
        data:{id:str},   
        url:url+"/screen_find_shot",
        type:'GET',
        dataType:'JSON',
        success:function (text) {
             anitabledata(text) ;
        },
        error:function () {
        }
    });
}

function anitabledata(text){
        document.getElementById("click_to_assets").innerHTML= "";
        document.getElementById("click_to_virsion").innerHTML= "";
        var listdata=eval('('+text+')');
        // var mytest =JSON.parse(listdata);
        var list = listdata.data;
        var datalength = list.length;
        var h='' ;
        h+= "<table class='table  table-border table-bordered table-bg  table-sort table-fixed-head'>" ;
        h+= "<th>id</th><th>预览图</th><th>镜头号</th><th>帧数</th><th>描述</th><th>状态</th><th>查看</th>" ;
        for(var i=0;i<datalength;i++){  
          var id = list[i]['id'] ;  
          h+="<tr onclick='sendshotid(this,"+id+")'>"   ;
          for(var row in list[i]){ 
            if(row!='status'){
                if(row=='mov_path'){
                     h+="<td>"+list[i][row];   
                }else if(row=='mov_picture_path')
                {
                 h+=list[i][row]+"</td>";   
                }else{
                  h+="<td>"+list[i][row]+"</td>";   
                }
            }else{
              h+="<td>"+ ani_show_status(list[i][row],id)+"</td>";
            }
          }   
          h+="<td><a onclick='myModalid("+id+")' class='btn btn-primary btn-lg' data-toggle='modal' data-target='#myModal'>查看link</a> </td></tr>";  
        } 
        h+="</table>" ;
      document.getElementById("click_to_assets").innerHTML= h;
}

function tabledata(text,item){
        $("#item03").html(item) ;
        document.getElementById("click_to_assets").innerHTML= "";
        document.getElementById("click_to_virsion").innerHTML= '';
        var listdata=eval('('+text+')');
        // var mytest =JSON.parse(listdata);
        var list = listdata.data;
        var datalength = list.length;
        var h='' ;
        h+= "<table  class='table' data-table-fixed-head-trigger='20' data-table-fixed-head-top='0'><thead id='thead'><tr><th></th><th colspan='10'><center>资产信息表</center></th></th></tr><tr class='text-c'><th  bgcolor='#FFFFFF' width='1%' >id</th><th  bgcolor='#FFFFFF' width='11%'>预览图片</th><th  bgcolor='#FFFFFF' width='11%'>资产英文名</th><th  bgcolor='#FFFFFF' width='8%' >资产中文名</th><th  bgcolor='#FFFFFF' width='7%' >制作人</th><th  bgcolor='#FFFFFF' width='8%' >描述</th><th  bgcolor='#FFFFFF' width='8%' >分类关键字</th><th  bgcolor='#FFFFFF' width='8%'>状态</th></tr></thead>"; 
        for(var i=0;i<datalength;i++){  
            var id = list[i]['id'] ;  
            h+="<tr   onclick='sendassetsid(this,"+id+")';>"   ;
        // obj.style.background = "#ccc";

          for(var row in list[i]){ 
            if(row=='status'){
                h+="<td>"+ show_status(list[i][row],id)+"</td>";
                // h+="<td>{"+list[i][row]+"</td>";
            }else{
               h+="<td>"+list[i][row]+"</td>";   
            }
          }  
          h+="</tr>";  
        }  
        h+="</table>" ;
        document.getElementById("click_to_assets").innerHTML=h;//将运算结果放到id为result的span节点中 
}

function ani_show_status(status, id, $field = 'id', $controller = '')
{
    switch (status) {
        // 恢复
        case 1 :
            $ret = '<a href="javascript:;" onclick="ajax_req(\'index/Shotapi/forbid/id/table_id\',{},change_status,[this,\'forbid\'])" class="label label-warning radius" title="有更新">有更新</a>';
            $ret=$ret.replace(/table_id/, id) ;
            break;
        // 禁用
        case 0 :
            $ret = '<a href="javascript:;" onclick="ajax_req(\'index/Shotapi/resume/id/table_id\',{},change_status,[this,\'resume\'])" class="label label-success radius" title="已经查看">已查看</a>';
            $ret=$ret.replace(/table_id/, id) ;
            break;
    //     // 还原
    //     case -1 :
    //         $ret = '<a href="javascript:;" onclick="ajax_req(\'index/recycle, [$field => '+$id]+') . '\')" class="label label-secondary radius" title="点击还原">还原</a>';
    //         break;
    }
    return $ret;
}

function show_status(status, id, $field = 'id', $controller = '')
{
    switch (status) {
        // 恢复
        case 1 :
            $ret = '<a href="javascript:;" onclick="ajax_req(\'index/index/forbid/id/table_id\',{},change_status,[this,\'forbid\'])" class="label label-warning radius" title="有更新">有更新</a>';
            $ret=$ret.replace(/table_id/, id) ;
            break;
        // 禁用
        case 0 :
            $ret = '<a href="javascript:;" onclick="ajax_req(\'index/index/resume/id/table_id\',{},change_status,[this,\'resume\'])" class="label label-success radius" title="已经查看">已查看</a>';
            $ret=$ret.replace(/table_id/, id) ;
            break;
    //     // 还原
    //     case -1 :
    //         $ret = '<a href="javascript:;" onclick="ajax_req(\'index/recycle, [$field => '+$id]+') . '\')" class="label label-secondary radius" title="点击还原">还原</a>';
    //         break;
    }
    return $ret;
}


function myModalid(str){
        $.ajax({
            data:{shot_id:str},   
            url:url+"/find_scene_link",
            type:'GET',
            dataType:'JSON',
            success:function (text) {
                 myModalcontent(text) ;
            },
            error:function (){
            }
        });
}

function sendassetsid(obj,str){
        tagscheck(obj) ;
        $.ajax({
        data:{id:str},   
        url:url+"/find_assets_version",
        type:'GET',
        dataType:'JSON',
        success:function (text) {
             versionstabledata(text) ;
        },
        error:function (){
        }
    });
}

function tagscheck(a) {
    var lng = document.getElementsByTagName("tr").length;
    for (i = 0; i < lng; i++) {
        var temp = document.getElementsByTagName("tr")[i];
        if (a == temp) {
            //选中的标签样式
            temp.style.background = "#ccc";
 
        } else {
            //恢复原状
            temp.style.background = "";
        }
 
    }
 
}

function sendshotid(obj,text){  
        tagscheck(obj) ;
        $.ajax({
        data:{id:text},   
        url:url+"/shot_find_version",
        type:'GET',
        dataType:'JSON',
        success:function(text) {
             versionstabledata01(text) ;
        },
        error:function (){

        }
    });
}

function myModalcontent(text){
        document.getElementById("myModalcontent").innerHTML='';//将运算结果放到id为result的span节点中 
        var listdata=eval('('+text+')');
        var list = listdata.data;
        var datalength = list.length;
        var h='' ;
        h+="" ;
        h+="<table class='table  table-border table-bordered table-bg  table-sort table-fixed-head'><tr><td>预览图片</td><td>资产英文名</td><td>资产中文名</td><td>制作人</td><td>描述</td><td>分类关键字</td><td>状态</td></tr><tr style='background: silver;'>"   ;
        for(var i=0;i<datalength;i++){  
          var k=0 ;
          for(var row in list[i]){  
            if(row!='id'){
                  if(row=='status'){
                    if(list[i]['status']==0){
                       h+="<td>有更新</td>";  
                    }else{
                       h+="<td>...</td>";  
                    }
                  }else{
                       h+="<td>"+list[i][row]+"</td>";  
                    }
                  } 
          }  
          h+="</tr><tr style='background: silver;'></tr>";  
        } 
        h+="<table>";  
        document.getElementById("myModalcontent").innerHTML=h;//将运算结果放到id为result的span节点中 
}


function versionstabledata(text){
        document.getElementById("click_to_virsion").innerHTML= '';
        var listdata=eval('('+text+')');
        var list = listdata.data;
        var datalength = list.length;
        var h='' ;
        h+="" ;
        for(var i=0;i<datalength;i++){  
            h+="<table class='table-border  table-bordered table-bg  table-sort'><tr><td with='70px'>版本号</td><td with='100px'>更新信息</td></tr>"   ;
            h+="<tr><td>"+list[i]['assets_versions_num']+"</td>"+"<td>"+list[i]['assets_description']+"</td></tr>";
            h+="<tr><td>提交时间</td><td>检查状态</td></tr><tr></tr>" ;
            h+="<tr><td>"+list[i]['create_time']+"</td>"+"<td>"+list[i]['check_status']+"</td></tr>";
            h+="<tr><td>bbox</td><td>长宽高</td></tr>"   ;
            h+="<tr><td>"+list[i]['bbox']+"</td>"+"<td>"+list[i]['overall_size']+"</td></tr>";
            h+="<tr><td>尺寸</td><td>点数量</td></tr>" ;
            h+="<tr><td>"+list[i]['size']+"</td>"+"<td>"+list[i]['points']+"</td></tr>";
            h+="<tr><td>面数量</td><td>边数量</td></tr>" ;
            h+="<tr><td>"+list[i]['faces']+"</td>"+"<td>"+list[i]['edges']+"</td></tr>";
            h+="<table>";  
            h+="<hr>";  
            h+="<hr>";  
        }  
        document.getElementById("click_to_virsion").innerHTML= h;
}

function versionstabledata01(text){

        var listdata=eval('('+text+')');
        // var mytest =JSON.parse(listdata);
        var list = listdata.data;
        var datalength = list.length;
        var h='' ;
        h+="<tr class='text-c'></tr>" ;

        for(var i=0;i<datalength;i++){  
            h+="<table class='table-border  table-bordered table-bg  table-sort'><tr><td with='70px'>版本号</td><td with='100px'>更新信息</td></tr>"   ;
            h+="<tr><td>"+list[i]['version_num']+"</td>"+"<td>"+list[i]['description']+"</td></tr>";
            h+="<tr><td>提交时间</td><td>检查状态</td></tr><tr></tr>" ;
            h+="<tr><td>"+list[i]['create_time']+"</td>"+"<td>"+list[i]['check_status']+"</td></tr>";
            h+="<table>";  
            h+="<hr>";  
            h+="<hr>"; 
        }   
        document.getElementById("click_to_virsion").innerHTML= h;
}
